package com.liangzhong.model.FameHall
{
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.model.FameHall.vo.FameHallVo;

	/**
	 * 荣誉堂  
	 * @author Administrator
	 * 
	 */	
	public class FameHallDateManager
	{
		/**
		 * 荣誉堂列表
		 */		
		private  var _fameHallList:Array;
		/**
		 *球员id数组 未激活
		 */		
		public var starIds 	:Array = [];
		
		public function FameHallDateManager()
		{
		}
		
		/**
		 *解析荣誉堂xml数据 
		 * 
		 */
		private function analysisXml():void
		{
			if(_fameHallList != null)return;
			_fameHallList = [];
			var xml:XML = ResourceManager.instance.getResource("tb_honour");
			
			var xmlList:XMLList = xml.children();
			var len:int = xmlList.length();
			var vo:FameHallVo;
			for(var i:int = 0;i < len;i++)
			{
				vo = new FameHallVo();
				vo.analysis(xmlList[i]);
				_fameHallList.push(vo);
				starIds.push(vo.palyerid_1);
				starIds.push(vo.palyerid_2);
				starIds.push(vo.palyerid_3);
			}
			_fameHallList.sort(sortList);
		}
		/**
		 *排序 
		 * @param a
		 * @param b
		 * @return 
		 * 
		 */		
		private function sortList(a:FameHallVo,b:FameHallVo):Number
		{
			if(a.honourid > b.honourid)return 1;
			if(a.honourid < b.honourid)return -1;
			return 0;
		}
		/**
		 *获取 荣誉数据 
		 * @return 
		 * 
		 */
		public function get fameHallList():Array
		{
			analysisXml();
			return _fameHallList;
		}
		
		/**
		 *获得荣誉堂数据 
		 * @param $arr
		 * 
		 */
		public function getFameHallInfo($arr:Array):void
		{
			analysisXml();
			var len:int = $arr.length;
			var obj:Object;
			var vo:FameHallVo;
			var starId :int;
			for(var i:int = 0;i < len;i++)
			{
				obj = $arr[i];
				vo = getFameHallVo(obj.honourid);
				if(vo == null)continue;
				vo.analysisObj(obj);
				starId = vo.starid1;
				if(starId > 0)
				{
					starIds.splice(starIds.indexOf(starId),1);
				}
				starId = vo.starid2;
				if(starId > 0)
				{
					starIds.splice(starIds.indexOf(starId),1);
				}
				starId = vo.starid3;
				if(starId > 0)
				{
					starIds.splice(starIds.indexOf(starId),1);
				}
			}
		}
		/**
		 * 放置球员  
		 * @param $obj   honourid  cellid  ntype
		 * @param $active
		 * 
		 */		
		public function putPlayer($obj:Object,$active:int):void
		{
			var vo:FameHallVo = getFameHallVo($obj.honourid);
			if(vo == null)return;
			var starId :int ;
			vo.active = $active;
			vo["starid"+$obj.ntype] = vo["palyerid_"+$obj.ntype];
			if(vo.active == 1)//放置球员返回，如果激活则可以领取奖励，如果没有激活，则不可以领取
			{
				vo.status = 1;
			}
			starId = vo["starid"+$obj.ntype];
			starIds.splice(starIds.indexOf(starId),1);
		}
		/**
		 *根据荣誉ID获取荣誉vo
		 *  
		 * @param $id
		 * 
		 */
		public function getFameHallVo($id:int):FameHallVo
		{
			for each(var vo:FameHallVo in _fameHallList)
			{
				if(vo.honourid == $id)return vo;
			}
			return null;
		}
		
		/**
		 *根据球员ID检测是否有此球员 
		 * @param $id
		 * 
		 */
		public function checkPlayerByID($id:int):Boolean
		{
			analysisXml();
			for each(var i:int in starIds)
			{
				if(i == $id)return true;
			}
			return false;
		}
	}
}